#include<iostream>
#include"httplib.h"
#include<stdio.h>
#include<cerrno>
int main(){
    httplib::Server ser;
    ser.Get("/hi",[](const httplib::Request& req,httplib::Response& res){
            res.set_content("hellp httplib","text/plain");//txt类型 set_content(const std::string &s, const char *content_type);
            res.status = 200;
            });
    ser.Get(R"(/number/(\d+))",[&](const httplib::Request& req,httplib::Response& res){
        auto num = req.matches[1];//matches中0下标保存的是整体path，往后下标保存的是捕获到的数据
        res.set_content(num,"text/plain");
        res.status = 200;
    });

    //post方法暂时无法测试，需要去客户端传多文件进行测试
    ser.Post("/multipart",[](const httplib::Request& req,httplib::Response& res){
            auto exist = req.has_file("file");            //判断是否存在文件
            if(exist==false){
            //std::cout<<"file not exist"<<std::endl;
            perror("file not exist");  
            res.status = 404;
            }
            std::cout<<1;
            //auto size = req.files.size();//获取文件大小
            const auto& file = req.get_file_value("file");
            res.body.clear();//初始化response体
            res.body+=file.filename+"\n";//返回文件名
            res.body+=file.content;//返回文件内容
            res.status = 200;
            });
    ser.listen("0.0.0.0",8081);
    return 0;

}   
